package com.hspedu.controller;

import com.hspedu.entity.Member;
import com.hspedu.entity.Result;
import com.hspedu.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.TimeUnit;

@Slf4j
@RestController
public class MemberController {

    @Resource
    private MemberService memberService;
    @GetMapping("/member/getMemberById")
    public Result getMemberById(@RequestParam("id")Long id, HttpServletRequest request){
        //String color = request.getParameter("color");
        //try {
        //    TimeUnit.SECONDS.sleep(5);
        //} catch (InterruptedException e) {
        //    throw new RuntimeException(e);
        //}
        Member member = memberService.queryById(id);
        if (member!=null){
            return Result.Success("查询会员成功，10001服务方",member);
        }else {
            return Result.Error("402","id="+id+"不存在");
        }

    }

    @PostMapping("/member/save")
    public Result save(@RequestBody Member member){
        log.info("member-service-provider.menber={}",member);
        int save = memberService.save(member);
        if (save>0){
            return Result.Success("添加会员成功",save);
        }else {
            return Result.Error("401","添加会员失败");
        }

    }


}
